//
//  WeightPickerViewController.m
//  IphoneFishApp
//
//  Created by erik on 2009-10-21.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "WeightPickerController.h"


@implementation WeightPickerController
@synthesize pickerView;
@synthesize arrayKG;
@synthesize arrayHG;
@synthesize actionSheet;
@synthesize kgValue;
@synthesize hgValue;
@synthesize parent;

- (void)viewDidLoad {
    [super viewDidLoad];
	kgValue = [[NSNumber alloc]initWithInt:0];
	hgValue = [[NSNumber alloc]initWithInt:1];
	
	NSLog(@"view did load");
	arrayKG = [[NSMutableArray alloc]init];
	[arrayKG addObject:@"0"];
	[arrayKG addObject:@"1"];
	[arrayKG addObject:@"2"];
	[arrayKG addObject:@"3"];
	[arrayKG addObject:@"4"];
	[arrayKG addObject:@"5"];
	[arrayKG addObject:@"6"];
	[arrayKG addObject:@"7"];
	[arrayKG addObject:@"8"];
	[arrayKG addObject:@"9"];
	[arrayKG addObject:@"10"];
	[arrayKG addObject:@"11"];
	[arrayKG addObject:@"12"];
	[arrayKG addObject:@"13"];
	[arrayKG addObject:@"14"];
	[arrayKG addObject:@"15"];
	[arrayKG addObject:@"16"];
	[arrayKG addObject:@"17"];
	[arrayKG addObject:@"18"];
	[arrayKG addObject:@"19"];
	[arrayKG addObject:@"20"];

	arrayHG = [[NSMutableArray alloc]init];
	
	[arrayHG addObject:@"1"];
	[arrayHG addObject:@"2"];
	[arrayHG addObject:@"3"];
	[arrayHG addObject:@"4"];
	[arrayHG addObject:@"5"];
	[arrayHG addObject:@"6"];
	[arrayHG addObject:@"7"];
	[arrayHG addObject:@"8"];
	[arrayHG addObject:@"9"];
}

-(IBAction)chooseWeight:(id)sender{
	UIActionSheet *weightSheet = [self actionSheet];
	[weightSheet dismissWithClickedButtonIndex:0 animated:YES];
	
	self.parent = (catchViewController *)self.parent;
	
	NSString *theWeight = [[NSString alloc]initWithFormat:@"%@.%@",kgValue,hgValue];
	NSLog(theWeight);
	
	[parent changeWeight:theWeight];
}

-(IBAction)cancelWeight:(id)sender{
	UIActionSheet *weightSheet = [self actionSheet];
	[weightSheet dismissWithClickedButtonIndex:0 animated:YES];
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
}


- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
	return 2;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
	if(component == 0){
		return [arrayKG count];
	}
	else{
		return [arrayHG count];
	}
}

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {	
	if(component == 0){
		return [arrayKG objectAtIndex:row];
	}
	else{
		return [arrayHG objectAtIndex:row];
	}
}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {		
	if(component == 0){
		self.kgValue = [arrayKG objectAtIndex:row];
	}
	else{
		self.hgValue = [arrayHG objectAtIndex:row];
	}
}

- (void)viewDidUnload {
	self.pickerView = nil;
	self.arrayKG = nil;
	self.arrayHG = nil;
	self.actionSheet = nil;
	self.parent = nil;
	self.kgValue = nil;
	self.hgValue = nil;
}

- (void)dealloc {
    [super dealloc];
	[pickerView release];
	[arrayHG release];
	[arrayKG release];
	[actionSheet release];
	[parent release];
	[kgValue release];
	[hgValue release];
}


@end
